/*
 * LeftRightValuesComparer.java
 *
 * Copyright(c) 2010
 * Michael Kroez
 * kroez@studiorutton.de
 *
 * All rights reserved.
 *
 * $Id$
 * 
 */

package de.studiorutton.gerengdic.dictionary.records;

import android.util.Log;

import edu.sdsu.util.Comparer;

public abstract class RecordComparer implements Comparer<LeftRightValuesRecord> {
	private final static String TAG = "learningwords";

	protected abstract RecordRankingValues getRank(LeftRightValuesRecord record);

//	protected abstract int getSize(LeftRightValuesRecord record);

	protected abstract String getValue(LeftRightValuesRecord lrvr, int position);

	public boolean greaterThan(LeftRightValuesRecord elem,
			LeftRightValuesRecord object) {
		RecordRankingValues elemRank = getRank(elem);
		RecordRankingValues objectRank = getRank(object);

		// Log.d( TAG, "Comparing '" + elem.getRightValuesAsString() +
		// "' *with* '" + object.getRightValuesAsString() + "'");
		int result = RecordRankingValues.comparator.compare(elemRank,
				objectRank);
		if (result == RecordRankingValues.GREATER_THAN)
			return true;
		else if (result == RecordRankingValues.LESS_THAN)
			return false;
		
		
		if (getValue(elem, elemRank.index).length() < getValue(object,
				objectRank.index).length())
			return false;
		else
			return true;
	}

	public boolean lessThan(LeftRightValuesRecord elem,
			LeftRightValuesRecord object) {
		return !greaterThan(elem, object) && !equals(elem, object);
	}

	public boolean equals(LeftRightValuesRecord elem,
			LeftRightValuesRecord object) {
		RecordRankingValues elemRank = getRank(elem);
		RecordRankingValues objectRank = getRank(object);

		int result = RecordRankingValues.comparator.compare(elemRank,
				objectRank);
		if (result != RecordRankingValues.EQUALS)
			return false;

		if (getValue(elem, elemRank.index).length() != getValue(object,
				objectRank.index).length())
			return false;
		else
			return true;
	}

}
